package com.project.collectAPI.entity.getBrandApi;

import com.project.collectAPI.comm.SpiderTools;
import com.project.collectAPI.entity.MeiTuan.SystemParam;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/* 获取美团指定品牌 APi */
@Data
public class getBrandAPI {

    private String reqAPI="https://waimaiopen.meituan.com/api/v1/gw/category/attr/value/list";

    //APP方门店id，即商家中台系统里门店的编码。如商家在操作绑定门店至开放平台应用中时，未绑定三方门店id信息，则默认APP方门店id与美团门店id相同。
    private Long attr_id;

    //统一的时间戳
    private Long timestamp;

    //查询的
    private String keyword;

    //页数
    private Integer page_num=1;

    //每页大小，最大支持200
    private Integer page_size=200;

    //签名
    private String signValue;


    /*获取美团类目接口签名*/
    public String getSign() throws Exception {
        SystemParam systemParam=new SystemParam();
        Map<String,Object> map=new HashMap<>();
        map.put("timestamp",timestamp);  //timestamp尽量统一用一次
        map.put("app_id",systemParam.getAppId());
        map.put("attr_id",attr_id);
        map.put("keyword",keyword);
        map.put("page_num",page_num);
        map.put("page_size",page_size);
        return systemParam.getSign(map,reqAPI); //获取签名
    }



    public String getBrands(){
        SystemParam systemParam=new SystemParam();
        String reqUrl=reqAPI+"?app_id="+systemParam.getAppId()+"&timestamp="+timestamp+"&sig="+signValue+"&attr_id="+attr_id+"&keyword="+keyword+"&page_num="+page_num+"&page_size="+page_size;
        System.out.println("地址:"+reqUrl);
        String res= SpiderTools.HttpGet(reqUrl);
        return res;
    }
}
